/**
 * 作者: hxl
 * 日期: 2025-07-24 16:25:04
 * 备注: 用户跨服限时商店表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.server.game.commondata.shop.Shop;
import com.motu.monstercity.server.game.commondata.shop.ShopConstant;
import com.motu.monstercity.server.game.logic.ShopManager;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.toolset.TimeUtils;

public class UserCrossRankActShop extends UserCrossRankActShopModel {
    public UserCrossRankActShop() {
        super();
    }

    public UserCrossRankActShop(long userId, int configId, long round, int shopId, int num) {
        putUserId(userId);
        putConfigId(configId);
        putRound(round);
        putShopId(shopId);
        putNum(num);
        String actListKey = EntityManager.getFieldJoinString(userId, configId);
        putActListKey(actListKey);
        putResetTime(TimeUtils.getCurTime());
    }

    public void reset() {
        Shop shop = ShopManager.getShop(shopId);
        if (shop == null) {
            return;
        }
        long curTime = TimeUtils.getCurTime();
        boolean update = false;
        if (shop.getLimitType() == ShopConstant.SHOP_LIMIT_TYPE_1) {
            if (!TimeUtils.isToday(resetTime)) {
                update = true;
            }
        } else if (shop.getLimitType() == ShopConstant.SHOP_LIMIT_TYPE_2) {
            if (!TimeUtils.isSameWeek(resetTime, curTime)) {
                update = true;
            }
        }
        if (update) {
            putNum(0);
            putResetTime(curTime);
            update();
        }
    }

    public void checkRound(long round) {
        if (getRound() != round) {
            putNum(0);
            putRound(round);
            putResetTime(TimeUtils.getCurTime());
            update();
        }
    }
}
